<template>
	<view class="default-background">
		<view class="submit-feedback-page">
			<view class="submit-item-group">
				<view class="close-btn">
					<uni-icons type="closeempty" size="30" @click="back"></uni-icons>
				</view>
				<view class="item-bar">我的反馈</view>
				<view class="item-group">
					<view class="item-input-group">
						<view class="item-input">{{feedback.title}}</view>
					</view>
				</view>
				<view class="item-group">
					<view class="item-input-group">
						<view class="item-input">{{feedback.content}}</view>
					</view>
				</view>
				<pf-img v-for="(url, index) in feedback.img" :src="url" @click.native="getImg(index)"></pf-img>
			</view>
			<view class="submit-item-group" v-if="feedback.reply">
				<view class="item-group" style="border-bottom: none;">
					<view class="item-bar">客服回复</view>
					<view class="item-input-group">
						<view class="item-input">{{feedback.reply}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config  from "@/config/app.js"
	export default {
		data() {
			return {
				id: "",
				feedback: {},
			};
		},
		methods: {
			back() {
				uni.navigateBack()
			},
			getImg: function(val) {
				console.log(val);
				const urls = this.feedback.img;
			  const current = val;
				uni.previewImage({
					urls,
					current,
					longPressActions: {
			      itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
			      },
						fail: function(err) {
							console.log(err.errMsg);
						},
					}
			  });
			},
			getFeedbackDetail() {
				this.$request.request({
					url: "/feedback/detail",
					method: "GET",
					data: {
						id: this.id
					}
				}).then(res=>{
					console.log(res);
					if (res.code == 200) {
						this.feedback = res.data
						if (this.feedback.img) {
							this.feedback.img = JSON.parse(this.feedback.img)
						}	
						// 为图片添加图片地址
						for (let i=0; i<this.feedback.img.length; i++) {
							this.feedback.img[i] = config.IMG_URL + this.feedback.img[i]
						}
					} else if (res.code == 401) {
						uni.navigateTo({
							url: "../user/login"
						})
					} else if (res.code == 403) {
						uni.showModal({
							title: res.message,
							showCancel: false,
							success(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: "./list"
									})
								}
							}
						})
					}
				})
			},
		},
		onLoad(option) {
			console.log("onload");
			this.id = option.id;
		},
		onShow() {
			console.log("onShow");
			this.getFeedbackDetail();
		}
	}
</script>

<style lang="scss">
	.submit-feedback-page {
		
		.submit-item-group {
			background-color: #FFFFFF;
			margin: 10rpx 10rpx;
			padding: 30rpx 20rpx;
			border-radius: 20rpx;
			
			.item-group {
				border-bottom: #f2f1f6 1rpx solid;
				
				.item-input-group {
					padding: 20rpx 0;
					
					.item-input {
						font-size: 16px;
						color: #000000;
						text-align: justify;
					}
				}
				
				.item-bar {
					font-size: 18px;
					margin-top: 10rpx;
				}
				
				.imgs {
					margin-top: 10rpx;
				}
			}
			
		}
		
	}

</style>